#include<iostream>
#include<vector>
#include<string>
using namespace std;


 // Definition for singly-linked list.
  struct ListNode {
      int val;
      ListNode *next;
      ListNode(int x) : val(x), next(NULL) {}
  };
 
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        if(head==NULL){
            return NULL;
        }
        ListNode* root = reverseList(head->next);
        head->next->next = head;
        head->next = NULL;
        return root;
    }
};


int main(){
    ListNode* head = new ListNode(1);
    head->next = new ListNode(2);
    head->next->next = new ListNode(3);
    head->next->next->next = new ListNode(4);
    Solution S;
    ListNode* root = S.reverseList(head);
    return 0;
}
